//src\main\preload.ts
const {contextBridge, ipcRenderer} = require('electron');

//将store挂载到window.electron下，待渲染进程调用
contextBridge.exposeInMainWorld('electron', {
  store: {
    getItem(key) {
        return ipcRenderer.sendSync('electron-store-get', key);
    },
    setItem(property, val) {
        ipcRenderer.send('electron-store-set', property, val);
    },
    path(){
        return ipcRenderer.sendSync('electron-store-path'); 
    },
  },
  async openCSV(){
    return await ipcRenderer.invoke('electron-get-csv');
  },
  async openNewWindow(url){
    ipcRenderer.send('open-window', url);
  },
  async saveFile(file){
    /**
     * file:{
     * data:data,
     * fileName:'测试',
     * filters:[{name:'JSON',extensions:['json']}]
     * }
     */
    ipcRenderer.send('save-file',file);
  },
  async readFiles(filters,multiSelections){
    return await ipcRenderer.invoke('read-file',filters,multiSelections);
  },
  // Other method you want to add like has(), reset(), etc.
});
